package com.alibaba.dubbo.remoting.interceptor;

import java.net.InetAddress;
import java.util.Map;

import com.alibaba.dubbo.remoting.Interceptor;
import com.alibaba.dubbo.remoting.RemoteCalling;

/**
 * 同时提供黑白名单支持
 * 优先判断白名单，然后判断黑名单
 * @author kingbo.ruan
 * @time 2014年9月25日 上午9:04:46
 */
public abstract class MixedListInterceptor implements Interceptor {

	@Override
	public boolean acceptAfterConnected(InetAddress remoteAddress) {
		if(matchWhite(remoteAddress)) return true;
		return !matchBlack(remoteAddress);
	}
	
	@Override
	public boolean acceptAfterDecodeHeader(InetAddress remoteAddress, Map<String, String> headers, int data) {
		return true;
	}
	
	
	@Override
	public boolean acceptAfterDecodeBody(InetAddress remoteAddress, Map<String, String> headers,
			RemoteCalling calling) {
		return true;
	}
	
	@Override
	public boolean acceptBeforeEncodeHeader(InetAddress remoteAddress, Map<String, String> headers) {
		return true;
	}
	
	@Override
	public boolean acceptBeforeEncodeBody(InetAddress remoteAddress, Map<String, String> headers) {
		return true;
	}
	
	@Override
	public boolean acceptAfterHead(InetAddress remoteAddress, int total, int body) {
		return true;
	}

	protected abstract boolean matchBlack(InetAddress address);
	protected abstract boolean matchWhite(InetAddress address);
}
